package com.lzm.ydpt.module.order.fragment;

import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.byt.framlib.base.BaseFragment;
import com.byt.framlib.basemvp.BasePresenter;
import com.byt.framlib.commonwidget.onclicktwo.AntiShake;
import com.byt.framlib.commonwidget.refresh.RefreshHeaderView;
import com.lzm.ydpt.R;
import com.lzm.ydpt.module.order.activity.PriceRulesActivity;
import com.lzm.ydpt.module.order.utils.OnPageCallBack;
import com.lzm.ydpt.module.riding.activity.MyInfoActivity;
import com.lzm.ydpt.module.riding.activity.PerAddressActivity;
import com.lzm.ydpt.view.pop.ContactPopWindows;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener;

import butterknife.BindView;
import butterknife.OnClick;


public class UserMineFragment extends BaseFragment implements ContactPopWindows.ListViewOnImtermClick {

    @BindView(R.id.srl_user_refresh)
    RefreshLayout srl_user_refresh;
    @BindView(R.id.rl_myinfo_layout)
    RelativeLayout rl_myinfo_layout;
    @BindView(R.id.img_user_pic)
    ImageView img_user_pic;
    @BindView(R.id.tv_user_name)
    TextView tv_user_name;

    private static UserMineFragment sFragment;
    private ContactPopWindows bottomPopWindows;
    private static OnPageCallBack mOnPageCallBack = null;

    public static UserMineFragment newsInstance(OnPageCallBack onPageCallBack) {
        sFragment = new UserMineFragment();
        mOnPageCallBack = onPageCallBack;
        return sFragment;
    }

    @Override
    protected int getLayoutResource() {
        return R.layout.fragment_user_mine;
    }

    @Override
    public BasePresenter initPresenter() {
        return null;
    }

    @Override
    protected void initView() {
        initRv();
    }

    private void initRv() {
        setRefreshLayout(srl_user_refresh);
        srl_user_refresh.setRefreshHeader(new RefreshHeaderView(context).getHeaderStyleStaffWhite());
        srl_user_refresh.setOnMultiPurposeListener(new SimpleMultiPurposeListener() {

            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                srl_user_refresh.finishRefresh(2000);
            }
        });
        srl_user_refresh.setEnableNestedScroll(false);
        srl_user_refresh.setEnableLoadMore(false);
    }

    @Override
    public void onDestroyView() {
        sFragment = null;
        super.onDestroyView();
    }

    @OnClick({R.id.rl_user_pic, R.id.tv_user_name, R.id.ll_order_list, R.id.ll_per_address, R.id.ll_price_rules, R.id.ll_contact_service})
    public void onClick(View view) {
        if (AntiShake.check(view.getId())) {
            return;
        }
        switch (view.getId()) {
            case R.id.rl_user_pic:
            case R.id.tv_user_name:
                openActivity(MyInfoActivity.class);
                break;
            case R.id.ll_order_list:
                if (mOnPageCallBack != null) {
                    mOnPageCallBack.pageCallBack(1);
                }
                break;
            case R.id.ll_per_address:
                openActivity(PerAddressActivity.class);
                break;
            case R.id.ll_price_rules:
                openActivity(PriceRulesActivity.class);
                break;
            case R.id.ll_contact_service:
                if (bottomPopWindows == null) {
                    bottomPopWindows = new ContactPopWindows(context, RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT, this);
                }
                bottomPopWindows.showPop(rootView);
                break;
        }
    }

    @Override
    public void onLvOnItem(String title) {
        callPhone(title);
    }
}